/*
 * @Author: long-xinyu2 2192763423@qq.com
 * @Date: 2025-04-01 10:09:57
 * @LastEditors: long-xinyu2 2192763423@qq.com
 * @LastEditTime: 2025-04-21 11:35:28
 * @FilePath: \algorithm\algorithm-training\lqb\acwing4_1.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
#include <bitset>
using namespace std;
using ull = unsigned long long;
using i128 = __int128_t;
//inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
#define int long long

const int N = 1010;

int f[N];

/*
%4 == 0 不变
%4 == 1 1
%4 == 3 0
%4 == 2 +1


*/
int get_XOR(int l,int r) {
	l--;int x,y;
	if(l%4==1) x=1;
	else if(l%4==3) x=0;
	else if(l%4==0) x=l;
	else x=l+1;
	if(r%4==1) y=1;
	else if(r%4==3) y=0;
	else if(r%4==0) y=r;
	else y=r+1;
	return (x^y);
}

void solve()
{  
    int l1,r1,l2,r2;
    cin >> l1 >> r1 >> l2 >> r2;
    if((r2 - l2 + 1) % 2 == 0 && (r1 - l1 + 1) % 2 == 0)
    {
        cout << 0 << endl;
        return;
    }
    else if((r2 - l2 + 1) % 2 == 1 && (r1 - l1 + 1) % 2 == 1)
    {
        cout << (get_XOR(l1,r1) ^ get_XOR(l2,r2)) << endl;
        return;
    }
    else if((r2 - l2 + 1) % 2 == 1 && (r1 - l1 + 1) % 2 == 0)
    {
        cout << get_XOR(l1,r1) << endl;
        return;
    }
    else if((r2 - l2 + 1) % 2 == 0 && (r1 - l1 + 1) % 2 == 1)
    {
        cout << get_XOR(l2,r2) << endl;
        return;
    }
}
signed main()
{
    int t = 1;
    cin >> t;
    while(t --)
    {
        solve();
    }
}
